package com.ruoyi.project.student.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.framework.aspectj.lang.annotation.DataScope;
import com.ruoyi.project.student.domain.Param.StudentListParam;
import com.ruoyi.project.student.domain.Student;
import com.ruoyi.project.student.domain.vo.StudentListVo;
import com.ruoyi.project.student.mapper.StudentMapper;
import com.ruoyi.project.student.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements StudentService {
    @Autowired
    private StudentMapper studentMapper;

    /**
     * 根据条件分页查询用户列表
     *
     * @param student 用户信息
     * @return 用户信息集合信息
     */
    @Override
    @DataScope(deptAlias = "d", userAlias = "u")
    public List<StudentListVo> selectStudentList(StudentListParam param)
    {
        return studentMapper.selectStudentList(param);
    }
//
//    @Override
//    @Transactional
//    public int insertStudent(Student student) throws Exception {
//        if(student.getName() ==null || student.getName().equals("")){
//            throw new Exception("姓名不能为空");
//        }
//        if(student.getNum() ==null || student.getNum().equals("")){
//            throw new Exception("学号不能为空");
//        }
//        int i = studentMapper.insertStudent(student);
//
//        return i;
//    }
//
//    @Override
//    @Transactional
//    public Student editStudent(Student student) throws Exception {
//        // 校验数据存在性
//        Student target = studentMapper.selectById(student.getId());
//        if (target == null) {
//            throw new Exception("学生不存在");
//        }
//
//        // 更新字段
//        target.setName(student.getName());
//        target.setNum(student.getNum());
//        target.setClassId(student.getClassId());
//
//        // 执行更新并检查结果
//        int updatedRows = studentMapper.editStudent(target);
//        if (updatedRows == 0) {
//            throw new Exception("更新失败，请检查数据");
//        }
//        return target;
//    }
//
//    @Override
//    @Transactional
//    public int delStudent(Student student) throws Exception {
//        return studentMapper.delStudent(student.getId());
//    }
}
